package com.cn.kafka.consumer;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;


/**
 * 接收消息的 消费者
 */
@Component
@Slf4j
public class Receiver {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    /**
     * 非自动提交，同一个主题，不同组
     * @param content
     */
    @KafkaListener(topics = "test1",groupId = "ni_hao_1")
    public void processMessage(String content) {
//        Message m =  JSON.parseObject(content, Message.class);
        log.info("ni_hao_1:"+content);
    }

    @KafkaListener(topics = "test1",groupId = "ni_hao_2")
    public void processMessage2(String content) {
//        Message m =  JSON.parseObject(content, Message.class);
        log.info("ni_hao_2:"+content);
    }

}

